package droid.frame.view;

import android.support.v4.widget.SwipeRefreshLayout;
import android.view.ViewTreeObserver.OnScrollChangedListener;
import android.widget.ScrollView;

/**
 * 解决 {@link SwipeRefreshLayout} 嵌套 {@link ScrollView} 等冲突的问题<br>
 * 用法 scrollView.getViewTreeObserver().addOnScrollChangedListener
 * 
 * @author coffee<br>
 *         2017-1-4下午4:01:06
 */
public class SwipeScrollViewOnScrollChangedListener implements OnScrollChangedListener {

	private ScrollView mScrollView;
	private SwipeRefreshLayout mSwipeLayout;

	public SwipeScrollViewOnScrollChangedListener(SwipeRefreshLayout swipeRefreshLayout, ScrollView scrollView) {
		this.mSwipeLayout = swipeRefreshLayout;
		this.mScrollView = scrollView;
	}

	@Override
	public void onScrollChanged() {
		int scrollY = mScrollView.getScrollY();
		if (scrollY == 0) {
			mSwipeLayout.setEnabled(true);
		} else {
			mSwipeLayout.setEnabled(false);
		}

	}

}
